#pragma once

#include<iostream>
#include<string>
#include"InetAddr.hpp"


//封装fd，保证一个fd一个缓冲区

class Reactor;
class Connection;
//原本是指向Channel的，这里换成Connection
// using handler_t = std::function<void(std::shared_ptr<Connection> channel)>;
using handler_t = std::function<std::string(std::string &)>;

//基类，listener是子类
class Connection
{
public:
    Connection():_events(0),_owner(nullptr)
    {}
    virtual void Recver() = 0;
    virtual void Sender() = 0;
    virtual void Excepter() = 0;
    virtual int GetSockFd() = 0;
    // std::string& Inbuffer();
    // void AppendOutBuffer(const std::string &out);
    void RegisterHandler(handler_t handler)
    {
        _handler = handler;
    }

    void SetEvent(const uint32_t &event)
    {
        _events = event;
    }
    // void SetSockFd(const int sockfd)
    // {
    //     _sockfd = sockfd;
    // }
    void SetOwner(Reactor *owner)
    {
        _owner = owner;
    }
    Reactor* GetOwner()
    {
        return _owner;
    }


    uint32_t GetEvent()
    {
        return _events;
    }

    // int GetSockFd()
    // {
    //     return _sockfd;
    // }

    ~Connection()
    {}
private:

    //回指指针
    Reactor *_owner;//用于在listener模块调用reactor模块里的addconnection

    //关心事件
    uint32_t _events;
public:
    handler_t _handler;

};